#import <Foundation/Foundation.h>
#import "DFVersion.h"

int print_functions() {
	printf("--diff\tCompare two Sophia Definitions\n");
	printf("--make\tCreate a C frontend for libdigifi from a Sophia Definition\n");
	
	return 0;
}

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    // check that we have one param to define the required functionality
	if (argc >= 2) {
		
		if (strcmp(argv[1], "--diff") == 0 ) {
			printf("Diff called\n");
		}
		else if (strcmp(argv[1], "--make") == 0 ) {
			printf("Make called\n");
			
			// check for two parameters
			if (argc == 4) {
				// process
				printf("Making\n");
				
				DFVersion *v = [[DFVersion alloc] initFromDefinition:[[NSString alloc] initWithCString:argv[2] encoding:NSASCIIStringEncoding]];
				
				[v printCommands];
				[DFTypePool printPool];
				
				for (DFCommand *p in v.commands) {
					if ([p isKindOfClass:[DFRowCommand class]]) {
					
						printf("%s: %s\n", [[p name] cString] , [[p typeMoniker] cString]);
						
					}
				}
				
			}
			else {
				printf("Not enough parameters for --make. The following required:\n");
				printf("1: Path to definition\n");
				printf("2: Path to directory for C files\n");
			}
		}
		else {
			// unknown
			printf("Function unknown select from:\n");
			print_functions();
		}
		
	} else {
		// unknown
		printf("At least one parameter required:\n");
		print_functions();
	}
	
    [pool drain];
    return 0;
}
